package jp.eisbahn.mgapi.api.people.lookup;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import jp.eisbahn.mgapi.api.AbstractRequest;
import jp.eisbahn.mgapi.api.Response;
import jp.eisbahn.mgapi.api.people.PeopleResponse;
import jp.eisbahn.mgapi.http.ContentType;
import jp.eisbahn.mgapi.http.HttpMethod;
import jp.eisbahn.mgapi.http.HttpUtils;
import jp.eisbahn.mgapi.util.StringUtils;

/**
 * The request class to retrieve the people information using e-mail addresses
 * with People lookup API.
 * @author Yoichiro Tanaka
 */
public class PeopleLookupRequest extends AbstractRequest {

    /** The base URI string. */
    private static final String BASE_URI = "/search/people?";

    /** E-mail addresses. */
    private String[] emails;

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getUri()
     */
    @Override
    public final String getUri() {
        String joined = StringUtils.join(emails, ",");
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("q", joined);
        String queryParameterString =
            HttpUtils.createQueryParameterString(parameterMap);
        return BASE_URI + queryParameterString;
    }

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getHttpMethod()
     */
    @Override
    public final HttpMethod getHttpMethod() {
        return HttpMethod.GET;
    }

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getResponseClass()
     */
    @Override
    public final Class<? extends Response> getResponseClass() {
        return PeopleResponse.class;
    }

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getContentType()
     */
    @Override
    public final ContentType getContentType() {
        return ContentType.X_WWW_FORM_URLENCODED;
    }

    /*
     * (non-Javadoc)
     * @see jp.eisbahn.mgapi.api.Request#getBodyStream()
     */
    @Override
    public final InputStream getBodyStream() {
        return null;
    }

    /**
     * Set e-mail addresses.
     * @param theEmails E-mail address array of String.
     */
    public final void setEmails(final String[] theEmails) {
        emails = theEmails;
    }

    /**
     * Retrieve e-mail addresses.
     * @return E-mail addresses array of String.
     */
    public final String[] getEmails() {
        return emails;
    }

}
